<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./test22.js"></script>
</head>
<body>
<script>

const onlineMembers = new Map([["40001", {}]])

function resetMember (member, index) {
    return {
        ...member,
        type: '1',
        title: `${member.personName || member.communicationName || `匿名${index}`}(${member.account})`,
        userId: member.account,
        treeId: member.id || member.personId,
    }
}

const random = (num = 10) => parseInt(Math.random() * Math.pow(10, num))

function breakDataSource(item) {
    const dispatchLength = item.dispatchList?.length
    item.title = `${item.orgName}[${item.count}]`;
    item.id = item.orgId;
    item.treeId = item.orgId;
    if (item.children) {
        item.children = item.children.map(breakDataSource);
        item.type = '0'
    }

    if (dispatchLength) {
        const id = `${random(10)}-${random(10)}`;
        item.children.unshift({
            id,
            treeId: id,
            title: `调度台[${dispatchLength}]`,
            children: item.dispatchList.map(resetMember),
        })
    }

    if (item.personList) {
        item.personList.map((member, index) => {
            item.children.push(resetMember(member, index))
        });
    }

    return item
}

const dataSource = datas.map(breakDataSource)
dataSource.map(console.log)
</script>
</body>
</html>